package com.peaker.advertisingpro.db

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.peaker.advertisingpro.BuildConfig
import com.peaker.advertisingpro.base.MyApplication
import com.peaker.advertisingpro.bean.*
import com.peaker.advertisingpro.db.dao.*


/**
 * room 数据库
 */
@Database(entities = [ProgramUrlBean::class, ResPlayNum::class,ProgramJsonBean::class,VolumeSet::class, InterPlayBean::class,SwitchDateBean::class], version = 9)
abstract class AppDatabase : RoomDatabase() {

    companion object {
        val instance: AppDatabase by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            Room.databaseBuilder(
                MyApplication.instance(),
                AppDatabase::class.java, "${BuildConfig.APPLICATION_ID}.db"
            )
                .allowMainThreadQueries() //允许在主线程访问数据库
                .fallbackToDestructiveMigration()//适用版本更新数据库
                .build()
        }

    }
    //节目 配置
    abstract fun programUrlDao(): ProgramUrlDao
    //资源播放统计
    abstract fun resPlayNumDao(): ResPlayNumDao
    //播放列表json
    abstract fun programJsonDao(): ProgramListJsonDao
    //插播内容
    abstract fun interPlayDao(): InterPlayDao
    //音量计划
    abstract fun volumeDao(): VolumePlanDao
    //开关机计划
    abstract fun switchDao(): SwitchDao

}